﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Customer.aspx.cs" Inherits="DevExpressWebApplication1.Module.CM.Customer" MasterPageFile="~/Main.master" %>

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <script type="text/javascript">
        function openAdd() {
            hdfCustomerID.Set("CusId", -1);
            ClearData();
            popupAddEdit.Show();
        }
        function EditCustomer() {
            // var key = gvCustomer.GetRowKey(gvCustomer.GetFocusedRowIndex());
            var index = gvCustomer.GetFocusedRowIndex();
            cbAddEdit.PerformCallback('Edit;' + index);
            popupAddEdit.Show();
        }
        function ClearData() {
            txtCustomer.SetValue('');
            txtCompany.SetValue('');
            txtPhone.SetValue('');
            txtAddress.SetValue('');
            dtpDOB.SetText('');
        }

    </script>
    <div class="span10">
        <dx:ASPxButton runat="server" ID="btnAdd" Text="Add" Theme="DevEx" UseSubmitBehavior="False" AutoPostBack="False">
            <ClientSideEvents Click="function(s,e){openAdd()}" />
        </dx:ASPxButton>
    </div>
    <div class="span10">
        <dx:ASPxGridView ID="gvCustomer" ClientInstanceName="gvCustomer" OnCustomCallback="gvCustomer_CustomCallback" ClientIDMode="Static"
            Width="100%" runat="server" AutoGenerateColumns="False" DataSourceID="dsCustomer" KeyFieldName="customer_id" Theme="DevEx">
            <Columns>
                <dx:GridViewDataTextColumn FieldName="customer_id" VisibleIndex="0" ReadOnly="True">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="customer_name" VisibleIndex="1">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="group_name" VisibleIndex="8">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="address" VisibleIndex="2">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="phone" VisibleIndex="3">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="dob" VisibleIndex="4">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="company" VisibleIndex="5">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="status" VisibleIndex="6" Visible="false">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="group_id" VisibleIndex="7" Visible="false">
                </dx:GridViewDataTextColumn>
             
            </Columns>
            <ClientSideEvents RowDblClick="function(s,e){ EditCustomer() }" />
            <SettingsBehavior AllowFocusedRow="True" />
        </dx:ASPxGridView>
    </div>
    <asp:SqlDataSource ID="dsCustomer" runat="server" ConnectionString="<%$ ConnectionStrings:PPL_ERPConnectionString %>" SelectCommand="sp_Customer_Select" ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
    <dx:ASPxPopupControl ID="popupAddEdit" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
        CssPostfix="Aqua" SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css" ClientInstanceName="popupAddEdit"
        HeaderText="Quản lý khách hàng" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" Theme="DevEx"
        EnableClientSideAPI="True" Width="650px" Height="200px">
        <%-- PopupElementID="divPotential" --%>
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl6" runat="server" SupportsDisabledAttribute="True">
                <div style="width: 100%">
                    <dx:ASPxCallbackPanel ID="cbAddEdit" ClientInstanceName="cbAddEdit" OnCallback="ASPxCallbackPanel1_Callback" runat="server" Width="100%">
                        <PanelCollection>
                            <dx:PanelContent>
                                <dx:ASPxHiddenField ID="hdfCustomerID" ClientInstanceName="hdfCustomerID" runat="server" />
                                <table width="100%">
                                    <tr>
                                        <td style="width: 20%">Tên khách hàng
                                        </td>
                                        <td style="width: 30%">
                                            <dx:ASPxTextBox ID="txtCustomer" ClientInstanceName="txtCustomer" runat="server" Theme="DevEx"></dx:ASPxTextBox>
                                        </td>
                                        <td style="width: 20%">Nhóm khách hàng
                                        </td>
                                        <td style="width: 30%">
                                            <dx:ASPxComboBox ID="cmbGroup" DataSourceID="dsCmbGetByType" ValueField="group_id" ValueType="System.Int32"
                                                IncrementalFilteringMode="Contains"  ClientInstanceName="cmbGroup" runat="server" Theme="DevEx">
                                                <Columns>
                                                    <dx:ListBoxColumn FieldName="group_name" />
                                                    <dx:ListBoxColumn FieldName="description" />
                                                </Columns>
                                            </dx:ASPxComboBox>
                                            <asp:SqlDataSource ID="dsCmbGetByType" runat="server" ConnectionString="<%$ ConnectionStrings:PPL_ERPConnectionString %>"
                                                SelectCommand="sp_Group_GetByType" SelectCommandType="StoredProcedure">
                                                <SelectParameters>
                                                    <asp:Parameter DefaultValue="1" Name="Type" Type="Int32" />
                                                </SelectParameters>
                                            </asp:SqlDataSource>

                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%">Tên công ty
                                        </td>
                                        <td style="width: 30%">
                                            <dx:ASPxTextBox ID="txtCompany" ClientInstanceName="txtCompany" runat="server" Theme="DevEx"></dx:ASPxTextBox>
                                        </td>
                                        <td>Điện thoại
                                        </td>
                                        <td>
                                            <dx:ASPxSpinEdit ID="txtPhone" ClientInstanceName="txtPhone" runat="server" Height="21px" Theme="DevEx" Number="0">
                                                <SpinButtons ShowIncrementButtons="false" />
                                            </dx:ASPxSpinEdit>
                                        </td>

                                    </tr>
                                    <tr>
                                        <td>Ngày sinh
                                        </td>
                                        <td>
                                            <dx:ASPxDateEdit ID="dtpDOB" ClientInstanceName="dtpDOB" runat="server" Theme="DevEx" EditFormat="Custom" EditFormatString="MM/dd/yyyy"></dx:ASPxDateEdit>
                                        </td>
                                        <td>Địa chỉ
                                        </td>
                                        <td>
                                            <dx:ASPxTextBox ID="txtAddress" ClientInstanceName="txtAddress" runat="server" Theme="DevEx"></dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="4">
                                            <dx:ASPxButton runat="server" Text="Cập nhật" UseSubmitBehavior="False" AutoPostBack="False">
                                                <ClientSideEvents Click="function(s,e){ gvCustomer.PerformCallback('Add'); }" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                            </dx:PanelContent>
                        </PanelCollection>
                    </dx:ASPxCallbackPanel>
                </div>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>
    <dx:ASPxCallback ID="cpReloadGrid" ClientInstanceName="cpReloadGrid" runat="server"
        OnCallback="cpReloadGrid_Callback">
        <ClientSideEvents CallbackComplete="function(s,e){SaveComplete(s,e);}" />
    </dx:ASPxCallback>
</asp:Content>

